package config

import (
	"fmt"
	"one-web/app/pkg/helper"

	"gopkg.in/ini.v1"
)

type server struct {
	Address string
	Port    int
	file    *ini.File
}

var Server *server

func (s *server) Load(path string) *server {

	var err error
	_, err = helper.PathExists(path)
	if err != nil {
		panic(err)
	}

	s.file, err = ini.Load(path)
	if err != nil {
		panic(err)
	}
	return s
}

func (s *server) Init() *server {
	fmt.Print("=======Init=========\n")
	if s.file == nil {
		return s
	}
	s.Address = s.file.Section("server").Key("address").MustString("0.0.0.0")
	s.Port = s.file.Section("server").Key("port").MustInt(8080)
	return s
}
